package com.coolweather.leo_anim;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class MainActivity3 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.acyivity_sd);

        //属性动画
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f,1f);
        valueAnimator.setDuration(2000);//设置显示时间
        //监听过程
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float value = (float) valueAnimator.getAnimatedValue();
                Log.e("","onAnimationUpdate"+value);
            }
        });
        valueAnimator.start();

        TextView textView = findViewById(R.id.textView);
                                                            // 资源 。。。。。。。。。。调用属性。。。。。变化范围(透明到不透明)
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView,"alpha",0f,1f);

        //时间
        objectAnimator.setDuration(4000);
        //设置开始
        objectAnimator.start();

        //监听器
        objectAnimator.addListener(new Animator.AnimatorListener() {
            //开始时调用
            @Override
            public void onAnimationStart(Animator animator) {

            }

            //结束时调用
            @Override
            public void onAnimationEnd(Animator animator) {

            }

            //动画取消时调用
            @Override
            public void onAnimationCancel(Animator animator) {

            }

            //重复执行时调用
            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });

        objectAnimator.addListener(new AnimatorListenerAdapter() {
            //效果同上面，只是可以自己选择实现几个方法
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
            }
        });
    }
}